package com.mpsc.spring.demo.controller;


import com.mpsc.api.bean.RoleInfoEntity;
import com.mpsc.api.common.BusinessException;
import com.mpsc.api.common.BaseResponse;
import com.mpsc.spring.demo.sevice.RoleInfoService;
import com.mpsc.spring.demo.vo.RoleInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/roleInfo")
@Api(value = "RoleInfoController", tags = "角色管理")
public class RoleInfoController {

    @Autowired
    private RoleInfoService roleInfoService;

    @PatchMapping("/save")
    @ApiOperation("保存用户信息")
    public void save(@RequestBody RoleInfoEntity role) {
        //测试spring事务问题
        roleInfoService.saveRoleInfo(role);
    }

    @PostMapping("/select")
    @ApiOperation("查询用户信息")
    public RoleInfoVo select(@RequestBody @Validated RoleInfoVo role) {
        System.out.println(role.toString());
        throw new BusinessException(404, "测试错误信息！");
        //return role;
        //return new BaseResponse(001002,"疯狂小豆丁",null);
    }

    @GetMapping("/select-one")
    @ApiOperation("查询用户信息")
    public BaseResponse selectOne(@RequestParam String name) {
        System.out.println(name);
        return new BaseResponse(001002, "疯狂小豆丁", null);
    }

}
